<template>
  <div>
    <el-dialog
      title="修改用户信息"
      @close="aditClosed"
      @open="getUserInfo"
      :visible.sync="dialogVisible"
      width="750px"
    >
      <el-form
        :model="getUsrInfoByID"
        :rules="rules"
        ref="changeRuleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="用户名" prop="username">
          <el-input disabled v-model="getUsrInfoByID.username"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="getUsrInfoByID.email"></el-input>
        </el-form-item>
        <el-form-item label="手机" prop="mobile">
          <el-input v-model.number="getUsrInfoByID.mobile"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="changeUserList">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { UserInfoRules } from '@/common/mixin'
import { getUserInfoByidApi, putUserInfoApi } from '@/Utils/Api/getUserInfoApi'
export default {
  name: 'changeUserBox',
  mixins: [UserInfoRules],
  props: {
    thisUserInfoId: {
      type: Number,
      default: 0
    }
  },
  data () {
    return {
      dialogVisible: false,
      getUsrInfoByID: {}
    }
  },
  components: {},
  created () {},
  mounted () {},
  methods: {
    async getUserInfo () {
      const { data } = await getUserInfoByidApi(this.thisUserInfoId)
      console.log(data)
      if (data.meta.status === 200) {
        this.getUsrInfoByID = data.data
      }
      console.log(this.getUsrInfoByID)
    },
    async changeUserList () {
      this.$refs.changeRuleForm.validate(async (vail) => {
        if (!vail) return
        const { data } = await putUserInfoApi(this.thisUserInfoId, {
          email: this.getUsrInfoByID.email,
          mobile: this.getUsrInfoByID.mobile
        })
        if (data.meta.status === 200) {
          this.dialogVisible = false
          this.$emit('changeUsrInfoDrive')
          return this.$message({
            type: 'success',
            message: data.meta.msg
          })
        } else {
          return this.$message({
            type: 'error',
            message: data.meta.msg
          })
        }
      })
    },
    // 关闭窗口后清空表单
    aditClosed () {
      this.$refs.changeRuleForm.resetFields()
    }
  },
  computed: {},
  watch: {}
}
</script>

<style scoped>
</style>
